// pages/temp/temp.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showOne: ['0'],
        show: false      
    },
    /**
     * 弹出套餐层
     */
    showPopup: function() {
        this.setData({
            show: true
        });
    },
    /**
     * 隐藏套餐层
     */
    onClose: function() {
        this.setData({
            show: false
        });
    },
    gopay: function (e) {
        // console.log(e.currentTarget.dataset.combo_type);
        // 套餐类型,1-月卡,0-次卡套餐
        var comboType = e.currentTarget.dataset.combo_type;
        // 获取用户信息缓存
        var cacheUserInfo = wx.getStorageSync('user_phone');

        wx.request({
          url: app.globalData.domain + 'v2/index/intoOrder',
          data: {
                combo_type: comboType,
                user_phone: (cacheUserInfo.phoneNumber && typeof (cacheUserInfo.phoneNumber) != 'undefined') ? cacheUserInfo.phoneNumber : ''
            },
            success: function (res) {
                console.log(res)
                if (res.data.code != 0) {
                    wx.showModal({
                        title: '温馨提示',
                        showCancel: false,
                        content: '支付系统繁忙,请稍后'
                    })
                    return ;
                }
                // 发起支付
                wx.requestPayment({
                    timeStamp: res.data.data.timeStamp,
                    nonceStr: res.data.data.nonceStr,
                    package: res.data.data.package,
                    signType: res.data.data.signType,
                    paySign: res.data.data.paySign,
                    success (res) {
                        console.log('debug支付成功');
                    },
                    fail (res) {
                        wx.showModal({
                            title: '温馨提示',
                            showCancel: false,
                            content: '支付失败!'
                        })
                        return ;                        
                    }
                })                
            }          
        })
    },    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    changeIcon(e) {
        let seq = e.currentTarget.dataset.seq;
        let arr = this.data.showOne;
        console.log(seq, arr.indexOf(seq));

        if (arr.indexOf(seq) > 0) {
            arr[seq] = 0;
            this.data.showOne = arr;
            this.setData({
                showOne: arr
            });
            console.log('有--删除::', arr, this.data.showOne);
        } else {
            arr[seq] = seq;
            this.data.showOne = arr;
            this.setData({
                showOne: arr
            });
            console.log('无--删除::', arr, this.data.showOne);
        }
        // if (this.data.showOne.seq.arrowIcon == 'https://aiw.oss-cn-beijing.aliyuncs.com/v3/xq_jt_n@2x.png') {
        //     this.data.showOne.seq.isShow = false;    
        //     this.data.showOne.seq.arrowIcon = 'https://aiw.oss-cn-beijing.aliyuncs.com/v3/xq_jt_s@2x.png';
        // } else {
        //     this.data.showOne.seq.isShow = true;    
        //     this.data.showOne.seq.arrowIcon = 'https://aiw.oss-cn-beijing.aliyuncs.com/v3/xq_jt_n@2x.png';
        // }
    }
})